<?php

  function tender_form_validation($form) {

    chkbadchar($form['title']['#value'], $form['title']['#title'], 'title');

	// maximum length validation for Title and Description Field
    maxlength_validation($form['title']['#value'], 255, $form['title']['#title'], 'title');

	// minimum length charcter
  	minilength_validation($form['title']['#value'], 5, $form['title']['#title'], 'title');
  	minilength_validation($form['field_ten_keywordc']['und'][0]['value']['#value'], 5, $form['field_ten_keywordc']['und'][0]['value']['#title'],'field_ten_keywordc');


	//Bad character validations
	chkbadchar($form['title']['#value'], $form['title']['#title'], 'title');
    chkbadchar($form['field_ten_keywordc']['und'][0]['value']['#value'], $form['field_ten_keywordc']['und'][0]['value']['#title'],'field_ten_keywordc');


    // Tender Reference number validation
    //check_integer($form['field_ten_refno'][0]['value']['#value'], $form['field_ten_refno']['#title'],                                                                           $form['field_ten_refno'][0]['#field_name']);

    //DIPR number validaiton

   //check_integer($form['field_ten_dipr'][0]['value']['#value'], $form['field_ten_dipr']['#title'],                                                                 $form['field_ten_dipr'][0]['#field_name']);


   // Tender Reference number And DIPR number
    maxlength_validation($form['field_ten_refno'][0]['value']['#value'], 255, $form['field_ten_refno']['#title'], 'field_ten_refno');
	maxlength_validation($form['field_ten_dipr'][0]['value']['#value'], 255, $form['field_ten_dipr']['#title'], 'field_ten_dipr');
	maxlength_validation($form['field_ten_keywordc'][0]['value']['#value'], 255, $form['field_ten_keywordc']['#title'], 'field_ten_keywordc');
  //date validtion

	//check_scheduler_date_expire($form['scheduler_settings']['unpublish_on']['date']['#value'],'Valid upto');
    //check_date_expire($form['field_ten_annosment_date'][0]['value']['date']['#value'],$form['field_ten_annosment_date']['#title']);

    //$ann_date = $form['field_ten_annosment_date'][0]['value']['date']['#value'];
    //$last_date = $form['field_ten_lastdate'][0]['value']['date']['#value'];
   // $open_date = $form['field_ten_openingdate'][0]['value']['date']['#value'];

    /*$flag = 0;
    $flag += check_date_expire($form['field_ten_annosment_date'],$ann_date);
    $flag += check_date_expire($form['field_ten_lastdate'],$last_date);
    $flag += check_date_expire($form['field_ten_openingdate'],$open_date);*/


   /* if ($ann_date != "" && $last_date != "" && dateDiff("-", $last_date, $ann_date) < 0 && $flag == 0) {
      form_set_error('field_ten_annosment_date', t('%expire_date is cannot be Lower than %start date',
                                                    array('%expire_date' => $form['field_ten_lastdate']['#title'],
                                                          '%start' => $form['field_ten_annosment_date']['#title'])));
      form_set_error('field_ten_lastdate',' ');
      //$flag += 1;
    }

    if ($last_date != "" && $open_date != "" && dateDiff("-", $open_date, $last_date) < 0 && $flag == 0) {
      form_set_error('field_ten_lastdate', t('%expire_date cannot be Lower than %start date',
                                                    array('%expire_date' => $form['field_ten_openingdate']['#title'],
                                                          '%start' => $form['field_ten_lastdate']['#title'])));
      form_set_error('field_ten_openingdate',' ');
    }
	$today = date("d-m-Y");
	if ($ann_date != "" && dateDiff("-", $ann_date, $today) < 0 && $flag == 0) {
      form_set_error('field_ten_annosment_date', t('%expire_date cannot be Lower %start date',
                                                    array('%expire_date' => $form['field_ten_annosment_date']['#title'],
                                                          '%start' => $today)));
      form_set_error('field_ten_openingdate',' ');
    }*/


  	// Availability Of Tender validation
  if ($form['field_ten_notice']['und']['#value'] == 'Online-Available') {
	  url_validation($form['field_ten_downladable']['und'][0]['value']['#value']);
	}


  if ($form['field_ten_notice']['und']['#value'] == 'Downloadble') {
	$filename = $form['field_ten_available']['und'][0]['#file'];
	$filename->filename;
    file_upload_validation_D7($filename->filename,$form['field_ten_notice']['und']['#title']);

  }


}



